package com.yanduo.beans

/**
  * 隐式转换
  * @author Gerry chan
  * 2020/5/3 15:35
  * @version 1.0
  */
class SheepString(val str: String) {
  def toIntPlus: Int = {
    try {
      str.toInt
    } catch {
      case _: Exception => 0
    }
  }


  def toDoublePlus: Double = {
    try {
      str.toDouble
    } catch {
      case _: Exception => 0
    }
  }

}

object SheepString{
  //知识点：Scala的隐式转换
  implicit def str2SheepString(str: String): SheepString = new SheepString(str)
}

